#pragma once

#include "EXButtonResSet.h"

#define _USE_TOOLTIP

typedef struct tagRADIO_GROUP
{
	CString strGroupName;
	CPtrList ptrList;
} RADIO_GROUP, * PRADIO_GROUP;

class AFX_EXT_CLASS CEXButton : public CButton
{
	DECLARE_DYNAMIC(CEXButton)

public:
	enum BUTTON_STYLE
	{
    NOIMAGE,
		PUSH_BUTTON,		// default button	
		CHECK_BUTTON,		// s states button
		RADIO_BUTTON,		// radio button
		CHECK_BOX,			// checkbox
    SKIN_BUTTON = 10,		// 4 states bitmap button
		SKIN_CHECK_BOX,
		SKIN_RADIO_BUTTON,
	};

public:
	CEXButton();
	virtual ~CEXButton();

	BOOL IsCurrentTab();
	void SetCurrentTab(BOOL bTab);
  void InitFont();
	BOOL IsTab();
	void SetTab(BOOL bTab);
	void SetTabPosition(int nPos);

	int GetCheck() const;
	void SetCheck(int nCheck);

	int GetRadioCheck();
	void SetRadioCheck(int nIndex = -1);

	// Bitmap Loding and Initialize
	BOOL SetBgBitmaps
		( 
		UINT id,          // ResourceID
		int count,        // Num Of Pics
		int TopHeight = 0,    // Top Merigin for Resizing
		int BottomHeight = 0, // Bottom Merigin for Resizing
		int LeftWidth = 0,    // Left Merigin for Resizing
		int RightWidth = 0    // Right Merigin for Resizing
		);

	BOOL SetBgBitmap(UINT nID, int nState);

	BOOL SetIconBitmaps(UINT id, int count,	int nLeft, int nTop);
	BOOL SetIconBitmaps(UINT id, int count,	BOOL bCenter);

	// Set Merigins
	void SetButtonDef( int TopHeight, int BottomHeight, int LeftWidth, 
                    int RightWidth );
	void SetBackColor( COLORREF color ) { m_BkColor = color; }
	COLORREF GetBackColor() { return m_BkColor; }
	void SetBkgndColor(COLORREF rcBkgnd);
	void SetBkgndColor(UINT nBkgnd);

	void SetStyle(BUTTON_STYLE nStyle);

	void SetHotButton(BOOL bSet = TRUE);
	void SetGradient(BOOL bSet = TRUE);
	void SetBoxFontSize(BOOL bSet = TRUE);
  void SetTextFont(CFont *font);
	BOOL AddRadioGroup(CString strGroupName);

	BOOL SetCheckBitmaps(UINT uCheckId, UINT uUncheckId, int nPiece = 4);
	BOOL SetRadioBitmaps(UINT uCheckId, UINT uUncheckId, int nPiece = 4);

	void SetCheckButton(BOOL bSet);

	BOOL SetToolTipText(CString strToolTip);

	void SetWindowRegion();
	void FlashButton();
  
  void SetResSet(CEXBaseResSet* pResSet);
  CEXButtonResSet* m_pbtnResSet;

protected:
	enum mode
	{
		normal  = 0,
		focus  = 1,
		select   = 2,
		disable = 3
	};

	enum state
	{
		notInited    = 0,
		FileLoaded   = 1,
		BitmapInited = 2
	};

	int m_State;

	// Bitmaps
	BOOL InitBgBitmap( CBitmap & src,int index, int count);
	BOOL InitIconBitmap( CBitmap & src, CBitmap & dist, int index, int count );

	void DrawBitmap( CDC * pDC, int mode );
	void DrawFrame(CDC * pDC, LPDRAWITEMSTRUCT lpDrawItemStruct);
	void DrawFrameDefault(CDC * pDC, LPDRAWITEMSTRUCT lpDrawItemStruct);
	void DrawFrameHot(CDC * pDC, LPDRAWITEMSTRUCT lpDrawItemStruct);
	void DrawFrameGradient(CDC * pDC, LPDRAWITEMSTRUCT lpDrawItemStruct);
	void DrawFrameCheckBox(CDC * pDC, LPDRAWITEMSTRUCT lpDrawItemStruct);
	void DrawFrameRadioButton(CDC * pDC, LPDRAWITEMSTRUCT lpDrawItemStruct);

	CBitmap m_bmpBg;
	CBitmap m_bmpIcon;

	int  m_nNumofBgPics; 
	UINT m_nBgId;       // Resource ID

	int m_nNumofIconPics;
	CPoint m_ptTopLeft;
	BOOL m_bSetIcon;
	UINT m_nIconId;       // Resource ID

	int m_TopHeight; //= 0;
	int m_BottomHeight; //= 0;
	int m_LeftWidth; //= 0;
	int m_RightWidth;// = 0;

	int m_dwWidth;
	int m_dwHeight;

  CFont m_ftBasic;
	// Transpararent BackColor
	COLORREF m_BkColor;

	UINT m_nBkgndColor;
	CBitmap m_bmpBkgnd;
	COLORREF m_crBkgnd;

	CFont * m_pFnt;
  COLORREF m_crfnt;
	BOOL m_bTracking;
	BOOL m_bEraseBkgnd;

	BOOL m_bCurrentTab;
	BOOL m_bTab;

	COLORREF m_crNormal;
	COLORREF m_crFocus;
	COLORREF m_crSelect;
	COLORREF m_crDisable;

	int m_nChecked;
	int m_nTextOffsetX;

	BUTTON_STYLE m_eButtonStyle;

	BOOL m_bHot;
	BOOL m_bGradient;
	BOOL m_bFontSize;

	CString m_strGroupName;
	static CPtrArray m_ptrArrRadio;

	BOOL m_bCenterIcon;

#ifdef _USE_TOOLTIP
	CToolTipCtrl m_Tooltip;
#endif // _USE_TOOLTIP

	CRgn m_rgnClient;

	BOOL m_bFlash;
	mode m_flash;

public:
	virtual void PreSubclassWindow();
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
	virtual BOOL PreTranslateMessage(MSG* pMsg);

protected:
	DECLARE_MESSAGE_MAP()
	afx_msg BOOL  OnEraseBkgnd(CDC* pDC);
public:
	afx_msg void OnKillFocus(CWnd* pNewWnd);
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg LRESULT OnMouseLeave(WPARAM, LPARAM);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnBnClicked();
	afx_msg void OnWindowPosChanging(WINDOWPOS* lpwndpos);
	afx_msg void OnTimer(UINT_PTR nIDEvent);
};


